<script  type="text/javascript">
$(function() {
        function submit_cluster_import(isforce){
                $(".table").find(".error_tip").hide();
		var bValid = true;

 	        bValid = bValid && checkLength( name, "名称", 3, 16);
                bValid = bValid && checkRegexp( name, /^[\u4e00-\u9fa50-9A-Za-z_-]+$/, "名称应由中文、大小写英文字母、数字、中划线(英文)或下划线构成.");

                bValid = bValid && checkipRegexp(node_ip, /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/i, "无效的IP地址.");
	        bValid = bValid && checkNull(link_pwd, "密码不能为空");

                if (isforce){
                    form_validation=true;  
                }
		if (bValid) {
		    $(".table .error_tip").hide();
		    $(".callback_tip").text("正在提交中......").css({"display":"block","color":'#000'});             		        
                    form_validation=false;  
		    $.post("/cluster",
                           {
                           'option':"{{option}}",
                            'name': $.trim(name.val()),
                            'password':$.trim(link_pwd.val()),
                            'node_ip':$.trim(node_ip.val()),
                            'isforce':isforce,
                           },

		           function(data){
                                if (data.reply.is_success){
			           form_validation=true;
                                }else{
                                    error =  data.reply.error;
                                    $(".callback_tip").css("display","block");
                                    $(".callback_tip").text(error);
                                    form_validation=true;
			       }
		           });
		}
        }
        $("#cluster_create_button").click(function(){ 
            submit_cluster_import(false) 
        });
        var form_validation=true;
        var name = $("#name"),
        node_ip=$("#cluster_node_ip"),
        link_pwd=$("#cluster_link_pwd");
});

</script>
<div class="panel panel-default">
    <div class="panel-body">
	<p>&nbsp;带<a class="high_tip_red">*</a>号的必填项</p>
        <div class="error_tip callback_tip  cluster_add_err_tip"></div>             	
	<table class="table">
         <tr class="tr-back">
             <td class="tb-item-name"><label for="name">集群别名:<a>*</a></label></td>  
             <td class="tb-item-value">
               <div>(由3至16位中文、大小写英文字母、数字、中划线(英文)或下划线构成)</div>
               <div class="error_tip"></div>             	
             	<input type="text" name="name" id="name" style='width:240px'/></td>       
         </tr>	                    
        <input style="display:none" type="text" />
        <input style="display:none" type="password"/>
          <tr>
              <td class="tb-item-name">
                  <label for="cluster_node_ip"><!--连接-->节点IP：<a>*</a></label>                
              </td>
              <td class="tb-item-value">
                 <!-- <div>(集群内可供管理系统连接的IP，通常是某一节点的外网IP)</div>  -->
                 <div>(集群内某一节点的IP)</div> 
                   <div  class="error_tip"></div>                                  
                  <input type="text" id="cluster_node_ip" name="cluster_node_ip"  autocomplete="off" style="width:240px"/>
              </td>
          </tr> 
         <tr class="tr-back">
               <td class="tb-item-name">
                  <label for="cluster_link_pwd">密码：<a>*</a></label>                               
               </td>       
               <td class="tb-item-value">
                <div>(连接节点root用户密码)</div>  
                 <div class="error_tip"></div>  
                   <input type="password" id="cluster_link_pwd" name="cluster_link_pwd" style="width:240px" />
               </td>  
         </tr>
	</table>
        <button type="button" class="btn btn-primary" id="cluster_create_button" >确定</button>
        <button type="button" class="btn btn-default">取消</button>
    </div> <!-- panel-body -->
</div>
